﻿using ExpressesClass.SfApi.Util;
using System.Xml;

namespace ExpressesClass.SfApi.Base
{
    public class Response
    {
        private string xml;
        public Response(string xml)
        {
            this.xml = xml;
        }
        public bool Result()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNode node = doc.DocumentElement.SelectSingleNode("Head");
            if (node.InnerText == "OK")
            {
                return true;
            }
            return false;
        }
        public T GetRes<T>()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNode node = doc.DocumentElement.SelectSingleNode("Body");
            return (T)XmlUtil.XmlToObj(node.InnerXml, typeof(T));
        }
        public string Err()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNode node = doc.DocumentElement.SelectSingleNode("ERROR");
            return node == null ? "" : node.InnerText;
        }
    }
}
